var express = require('express');
let maileConfig = require("./maileConfig");
var router = express.Router();
const LocalStorage = require('node-localstorage').LocalStorage,

  localStorage = new LocalStorage('./scratch');
/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource');
});
// 登录
router.get('/login', function (req, res, next) {
  res.send({
    code: 111,
    msg: "登录"
  });
});

// 发送邮件的接口
router.get('/email', function (req, res, next) {

  let email = req.query.email;
  let code = createSixNum();
  console.log(code);

  var mail = {
    // 发件人
    from: '<1192719918@qq.com>',
    // 主题
    subject: '验证码',//邮箱主题
    // 收件人
    to: email,//前台传过来的邮箱
    // 邮件内容，HTML格式
    text: '用' + code + '作为你的验证码'//发送验证码
  };
  maileConfig(mail)
  res.send({
    code: 1,
    msg: "发送成功"
  })
  // 随机产生六位验证码
  function createSixNum() {   
    var Num = "";
    for (var i = 0; i < 6; i++) {
      Num += Math.floor(Math.random() * 10);
    }
    return Num;
  }
});
module.exports = router;
